
package com.joysuch.wwyt.datadump.biz.convertor;

import cn.zlg.common.datadump.annotation.DataDumpField;
import cn.zlg.common.datadump.convertor.FieldValueConvert;
import cn.zlg.common.datadump.service.JPABatchQueryPropertyValueService;
import com.joysuch.wwyt.core.entity.BaseTypeGroupItem;
import com.joysuch.wwyt.core.entity.dsl.QBaseTypeGroup;
import com.joysuch.wwyt.core.entity.dsl.QBaseTypeGroupItem;
import com.joysuch.wwyt.core.repository.BaseTypeGroupItemDao;
import com.querydsl.core.Tuple;
import com.querydsl.core.types.dsl.NumberPath;
import com.querydsl.jpa.impl.JPAQueryFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

@Component
public class ExportBaseTypeGroupItemNameConvertor implements FieldValueConvert<Long, String> {

    @Autowired
    private JPABatchQueryPropertyValueService<BaseTypeGroupItem,Long,String> batchQueryService;

    @Autowired
    private BaseTypeGroupItemDao dao;

    @Override
    public String convert(Object bean, Long value, DataDumpField dataField) {
        return dao.findNameById(value);
    }

    public boolean supportBatch() {
        return true;
    }

    public List<String> convert(List<Object> bean, List<Long> value, DataDumpField dataDumpField) {
        if(value == null || value.isEmpty()) {
            return Collections.EMPTY_LIST;
        }
        QBaseTypeGroupItem q = QBaseTypeGroupItem.baseTypeGroupItem;
        return batchQueryService.query(q, q.id, q.name, value);
    }
}
